#include"touch.h"
#include"lcd.h"
#include"bmp.h"
#include"video.h"
#include"music.h"
#include"dir.h"
int retrieve_file(char *file_path,char file_name[][256],char *file_type,int max_num)
{
    int index = 0;
    DIR *dp = opendir(file_path);
    if (dp == NULL)
    {
        fprintf(stderr,"opendir() failed:%s\n",strerror(errno));
        return -1;
    }
    // 读取每个目录项，并输出各个文件的名称
    struct dirent *ep;
    struct stat st;
    stat(file_path,&st);
    while(1)
    {
        ep = readdir(dp);
        if(ep == NULL )
        {
            if (errno != 0)
            {
                printf("readdir failed\n");
            }
            break;
        }
        if (ep->d_type == DT_REG && strstr(ep->d_name,file_type) != NULL && index < max_num)
        {
            snprintf(file_name[index++],256,"%s/%s",file_path,ep->d_name);
        }
    }
    closedir(dp);
    return index;
}